/*
 * Die.java
 *
 * This file is part of Frontgammon.
 *
 * Frontgammon is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Frontgammon is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Frontgammon.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Created on October 1, 2007, 4:03 PM
 */

package edu.lamar.frontgammon.client.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Random;

/**
 *
 * @author  James
 */
public class Die extends javax.swing.JPanel {
     
    public int val = 6;
    /** Creates new form Die */
    public Die() {
        initComponents();         
        
       }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
        setMinimumSize(new java.awt.Dimension(30, 30));
        setPreferredSize(new java.awt.Dimension(30, 30));
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 24, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 24, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
    
    
    @Override public void paintComponent(Graphics graphics) {
        super.paintComponent(graphics);
        
        Graphics2D g = (Graphics2D)graphics;
        
        Color borderColor = Color.GRAY;
        Color fillColor = Color.BLACK;
        
        int circleDiameter = Math.min(this.getBounds().width, this.getBounds().height) / 6;
        int width = this.getBounds().width;
        int height = this.getBounds().height;
        int centerX = this.getBounds().width / 2;
        int centerY = this.getBounds().height / 2;
        int radius = (circleDiameter / 2);
        
        
        // This switch statement is filled with fun. I especially love the "value - radius + radius" parts.
        // Never wait until the last minute to code.
        switch (val) {
            case 1:
                g.setColor(fillColor);
                g.fillOval(centerX - radius, centerY - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval(centerX - radius, centerY - radius, circleDiameter, circleDiameter);
                break;
                
            case 2:
                // Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, centerY - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, centerY - radius, circleDiameter, circleDiameter);
                
                // Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, centerY - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, centerY - radius, circleDiameter, circleDiameter);
                break;

            case 3:
                // Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                
                // Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                
                // Upper
                g.setColor(fillColor);
                g.fillOval(centerX - radius, height / 3 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval(centerX - radius, height / 3 - radius, circleDiameter, circleDiameter);
                break;

            case 4:
                // Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                
                // Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                
                // Upper Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, height / 3 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, height / 3 - radius, circleDiameter, circleDiameter);
                
                // Upper Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, height / 3 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, height / 3 - radius, circleDiameter, circleDiameter);
                break;
                
            case 5:
                // Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                
                // Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, height / 3 * 2 - radius, circleDiameter, circleDiameter);
                
                // Upper Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, height / 3 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, height / 3 - radius, circleDiameter, circleDiameter);
                
                // Upper Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, height / 3 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, height / 3 - radius, circleDiameter, circleDiameter);
                
                // Middle
                g.setColor(fillColor);
                g.fillOval(centerX - radius, centerY - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval(centerX - radius, centerY - radius, circleDiameter, circleDiameter);
                break;
                
            case 6:
                // Lower Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, height / 4 * 1 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, height / 4 * 1 - radius, circleDiameter, circleDiameter);
                
                // Lower Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, height / 4 * 1 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, height / 4 * 1 - radius, circleDiameter, circleDiameter);
                
                // Middle Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, height / 4 * 2  - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, height / 4 * 2 - radius, circleDiameter, circleDiameter);
                
                // Middle Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, height / 4 * 2 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, height / 4 * 2 - radius, circleDiameter, circleDiameter);
                
                // Upper Left
                g.setColor(fillColor);
                g.fillOval((centerX / 2) - radius + radius, height / 4 * 3 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((centerX / 2) - radius + radius, height / 4 * 3 - radius, circleDiameter, circleDiameter);
                
                // Upper Right
                g.setColor(fillColor);
                g.fillOval((width / 4) * 3 - radius - radius, height / 4 * 3 - radius, circleDiameter, circleDiameter);
                g.setColor(borderColor);
                g.drawOval((width / 4) * 3 - radius - radius, height / 4 * 3 - radius, circleDiameter, circleDiameter);
                break;
        }
    }
}
